{{define "content"}}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h2><i class="fas fa-list me-2"></i>模型配置列表</h2>
    <a href="/admin/create" class="btn btn-primary">
        <i class="fas fa-plus me-2"></i>新增配置
    </a>
</div>

<!-- 筛选器 -->
<div class="card mb-4">
    <div class="card-body">
        <form method="GET" action="/admin" class="row g-3">
            <div class="col-md-4">
                <label for="model_type" class="form-label">模型类型</label>
                <select class="form-select" name="model_type" id="model_type">
                    <option value="">全部</option>
                    <option value="llm" {{if eq .Filters.ModelType "llm"}}selected{{end}}>LLM</option>
                    <option value="embedding" {{if eq .Filters.ModelType "embedding"}}selected{{end}}>Embedding</option>
                    <option value="reranker" {{if eq .Filters.ModelType "reranker"}}selected{{end}}>Reranker</option>
                </select>
            </div>
            <div class="col-md-4">
                <label for="enabled" class="form-label">启用状态</label>
                <select class="form-select" name="enabled" id="enabled">
                    <option value="">全部</option>
                    <option value="1" {{if eq .Filters.Enabled "1"}}selected{{end}}>启用</option>
                    <option value="0" {{if eq .Filters.Enabled "0"}}selected{{end}}>禁用</option>
                </select>
            </div>
            <div class="col-md-4 d-flex align-items-end">
                <button type="submit" class="btn btn-outline-primary me-2">
                    <i class="fas fa-filter me-1"></i>筛选
                </button>
                <a href="/admin" class="btn btn-outline-secondary">
                    <i class="fas fa-refresh me-1"></i>重置
                </a>
            </div>
        </form>
    </div>
</div>

<!-- 配置列表 -->
<div class="card">
    <div class="card-body">
        {{if .Data.List}}
        <div class="table-responsive">
            <table class="table table-hover">
                <thead class="table-light">
                    <tr>
                        <th>ID</th>
                        <th>供应商</th>
                        <th>模型名称</th>
                        <th>模型类型</th>
                        <th>模型路径</th>
                        <th>状态</th>
                        <th width="200">操作</th>
                    </tr>
                </thead>
                <tbody>
                    {{range .Data.List}}
                    <tr>
                        <td>{{.ID}}</td>
                        <td>
                            <div class="d-flex align-items-center">
                                {{if .VendorImg}}
                                <img src="{{.VendorImg}}" alt="{{.VendorCN}}" class="vendor-logo me-2" width="24" height="24">
                                {{else}}
                                <i class="fas fa-cube me-2 text-muted"></i>
                                {{end}}
                                <div>
                                    <div class="fw-bold">{{.VendorCN}}</div>
                                    <small class="text-muted">{{.VendorEN}}</small>
                                </div>
                            </div>
                        </td>
                        <td>
                            {{if .ModelName}}
                                <span class="badge bg-info">{{.ModelName}}</span>
                            {{else}}
                                <span class="text-muted">-</span>
                            {{end}}
                        </td>
                        <td>
                            {{if eq .ModelType "llm"}}
                                <span class="badge bg-primary">LLM</span>
                            {{else if eq .ModelType "embedding"}}
                                <span class="badge bg-success">Embedding</span>
                            {{else if eq .ModelType "reranker"}}
                                <span class="badge bg-warning">Reranker</span>
                            {{else}}
                                <span class="badge bg-secondary">{{.ModelType}}</span>
                            {{end}}
                        </td>
                        <td>
                            <small class="text-truncate d-inline-block" style="max-width: 200px;" title="{{.ModelPath}}">
                                {{.ModelPath}}
                            </small>
                        </td>
                        <td>
                            {{if eq .Enabled 1}}
                                <span class="badge bg-success">
                                    <i class="fas fa-check-circle me-1"></i>启用
                                </span>
                            {{else}}
                                <span class="badge bg-danger">
                                    <i class="fas fa-times-circle me-1"></i>禁用
                                </span>
                            {{end}}
                        </td>
                        <td>
                            <div class="btn-group btn-group-sm" role="group">
                                <a href="/admin/view/{{.ID}}" class="btn btn-outline-info" title="查看">
                                    <i class="fas fa-eye"></i>
                                </a>
                                <a href="/admin/edit/{{.ID}}" class="btn btn-outline-primary" title="编辑">
                                    <i class="fas fa-edit"></i>
                                </a>
                                <button type="button" class="btn btn-outline-success" onclick="testModel('{{.ModelType}}', '{{if .ModelName}}{{.ModelName}}{{else}}{{.VendorEN}}{{end}}')" title="测试模型">
                                    <i class="fas fa-flask"></i>
                                </button>
                                <button type="button" class="btn btn-outline-warning" onclick="toggleStatus({{.ID}})" title="切换状态">
                                    <i class="fas fa-power-off"></i>
                                </button>
                                <button type="button" class="btn btn-outline-danger" onclick="deleteConfig({{.ID}})" title="删除">
                                    <i class="fas fa-trash"></i>
                                </button>
                            </div>
                        </td>
                    </tr>
                    {{end}}
                </tbody>
            </table>
        </div>

        <!-- 分页 -->
        {{if gt .Data.Total 0}}
        <nav class="mt-4">
            <ul class="pagination justify-content-center">
                {{$currentPage := .Data.Page}}
                {{$totalPages := .TotalPages}}
                {{$filters := .Filters}}
                
                <!-- 上一页 -->
                {{if gt $currentPage 1}}
                <li class="page-item">
                    <a class="page-link" href="?page={{sub $currentPage 1}}&model_type={{$filters.ModelType}}&enabled={{$filters.Enabled}}">上一页</a>
                </li>
                {{end}}

                <!-- 页码 -->
                {{range $i := .PageRange}}
                <li class="page-item {{if eq $i $currentPage}}active{{end}}">
                    <a class="page-link" href="?page={{$i}}&model_type={{$filters.ModelType}}&enabled={{$filters.Enabled}}">{{$i}}</a>
                </li>
                {{end}}

                <!-- 下一页 -->
                {{if lt $currentPage $totalPages}}
                <li class="page-item">
                    <a class="page-link" href="?page={{add $currentPage 1}}&model_type={{$filters.ModelType}}&enabled={{$filters.Enabled}}">下一页</a>
                </li>
                {{end}}
            </ul>
        </nav>
        
        <div class="text-center text-muted mt-2">
            共 {{.Data.Total}} 条记录，第 {{.Data.Page}}/{{.TotalPages}} 页
        </div>
        {{end}}
        {{else}}
        <div class="text-center py-5">
            <i class="fas fa-inbox fa-3x text-muted mb-3"></i>
            <h5 class="text-muted">暂无数据</h5>
            <p class="text-muted">还没有任何模型配置，点击上方按钮创建第一个配置吧！</p>
        </div>
        {{end}}
    </div>
</div>
{{end}}
